* FIG 8: EVOLUTION OF TAX REVENUE IN OW COMPARED TO OTHER CANTONS


version 16.1

clear
cap log close 
cap clear matrix
set more off
graph drop _all
set scheme mygraphs


use "$mypathRR/Datasets/revenuedata_ktn.dta", clear

*--------------------------------------------------------------------------------------
**** GENERATE YEAR-TO-YEAR CHANGE IN DIFFERENT REVENUE TYPES   ***

//gen revenue share
replace revCH_total=rev_total if canton==0 & revCH_total==.
gen rev_sh_total=rev_total/revCH_total

replace revCentral_total=rev_total if canton==28 & revCentral_total==.
gen rev_shCent_total=rev_total/revCentral_total


replace revCH_all_rev=rev_all_rev if canton==0 & revCH_all_rev==.
gen rev_sh_all_rev=rev_all_rev/revCH_all_rev

replace revCentral_all_rev=rev_all_rev if canton==28 & revCentral_all_rev==.
gen rev_shCent_all_rev=rev_all_rev/revCentral_all_rev



replace revCH_corp_total=rev_corp_total if canton==0 & revCH_corp_total==.
gen rev_sh_corp_total=rev_corp_total/revCH_corp_total

replace revCentral_corp_total=rev_corp_total if canton==28 & revCentral_corp_total==.
gen rev_shCent_corp_total=rev_corp_total/revCentral_corp_total



replace revCH_weatax = rev_weatax if canton == 0 & revCH_weatax ==.
gen rev_sh_weatax = rev_weatax / revCH_weatax


replace revCH_inctax = rev_inctax if canton == 0 & revCH_inctax ==.
gen rev_sh_inctax = rev_inctax / revCH_inctax


// gen revenue growth
sort canton  year
bys canton : gen rev_gr_total=(rev_total[_n]-rev_total[_n-1])/rev_total[_n-1]

gen revCH_gr_total= rev_gr_total if canton == 0
bys year (canton): replace revCH_gr_total = revCH_gr_total[_n-1] if revCH_gr_total[_n-1] !=.


sort canton  year
bys canton : gen rev_gr_all_rev=(rev_all_rev[_n]-rev_all_rev[_n-1])/rev_all_rev[_n-1]

gen revCH_gr_all_rev= rev_gr_all_rev if canton == 0
bys year (canton): replace revCH_gr_all_rev = revCH_gr_all_rev[_n-1] if revCH_gr_all_rev[_n-1] !=.


sort canton  year
bys canton : gen rev_gr_corp_total=(rev_corp_total[_n]-rev_corp_total[_n-1])/rev_corp_total[_n-1]

gen revCH_gr_corp_total= rev_gr_corp_total if canton == 0
bys year (canton): replace revCH_gr_corp_total = revCH_gr_corp_total[_n-1] if revCH_gr_corp_total[_n-1] !=.


// gen growth normalized by Swiss growth
gen norm_rev_gr_total = rev_gr_total/revCH_gr_total

gen norm_rev_gr_all_rev = rev_gr_all_rev/revCH_gr_all_rev

gen norm_rev_gr_corp_total = rev_gr_corp_total/revCH_gr_corp_total


// gen an index
foreach var in rev_total revCH_total revCentral_total   rev_all_rev revCH_all_rev revCentral_all_rev rev_corp_total revCH_corp_total revCentral_corp_total {
	gen `var'2005 = `var' if year==2005
	format `var'2005 %10.0g
}

sort canton  year
foreach var in rev_total2005 revCH_total2005 revCentral_total2005   rev_all_rev2005 revCH_all_rev2005 revCentral_all_rev2005   rev_corp_total2005 revCH_corp_total2005 revCentral_corp_total2005 {
  bys canton : replace `var' = `var'[_n-1] if `var'==.
	forval i=1/15 {
	  display `i'
	  bys canton : replace `var' = `var'[_n+1] if `var'==.
	}
}


foreach var in rev_total revCH_total revCentral_total   rev_all_rev revCH_all_rev revCentral_all_rev   rev_corp_total revCH_corp_total revCentral_corp_total {
  gen `var'_index =`var'/`var'2005*100
  label var `var'_index "Total tax revenue (2005=100)"
  drop `var'2005
}

rename *_total_index *_index


// label vars
label var rev_gr_total "Annual growth in personal cantonal tax rev."
label var rev_sh_total "Share in total personal cantonal tax rev."
label var rev_shCent_total "Share in regional personal cantonal tax rev."
label var norm_rev_gr_total "Cantonal/Swiss income tax revenue growth ratio"


label var rev_gr_all_rev "Annual growth in total cantonal rev."
label var rev_sh_all_rev "Share in total total cantonal rev."
label var rev_shCent_all_rev "Share in regional total cantonal rev."
label var norm_rev_gr_all_rev "Cantonal/Swiss total cantonal revenue growth ratio"

label var rev_sh_weatax "Share in cantonal wealth tax rev."
label var rev_sh_inctax "Share in cantonal income tax rev."


label var rev_gr_corp_total "Annual growth in corporate cantonal tax rev."
label var rev_sh_corp_total "Share in total corporate cantonal tax rev."
label var rev_shCent_corp_total "Share in regional corporate cantonal tax rev."
label var norm_rev_gr_corp_total "Cantonal/Swiss corporate tax revenue growth ratio"

// shift year +0.15 for nice display of graphs
replace year=year+0.15

*--------------------------------------------------------------------------------------
*--------------------------------------------------------------------------------------
* GRAPH WITH TOTAL REVENUE

cd "$mypathRR/Results"

foreach var in weatax inctax total corp_total all_rev {
	
	if "`var'" == "all_rev" {
	local legpos ring(0) position(5)
	}
	else {
	local legpos ring(0) position(11)
	}


mylabels 0(0.05)0.4, myscale(@/100) suffix("%") local(myla)

	preserve
	replace rev_`var' = rev_`var' / 1000
	label var rev_weatax "Cantonal wealth tax rev. (mio CHF)"
	label var rev_inctax "Cantonal income tax rev. (mio CHF)"
	label var rev_all_rev "Total cantonal rev. (mio CHF)"
	label var rev_total "Cantonal personal tax rev. (mio CHF)"
	label var rev_corp_total "Cantonal corporate tax rev. (mio CHF)"

	graph twoway (line rev_sh_`var' year if canton==6, lwidth(*2.3)) ///
	(line rev_`var' year if canton==6, yaxis(2) lpattern(dash) lwidth(*2.3)) , ///
	xtitle("") xline(2006) xline(2008, lcolor(green)) xline(2002, lcolor(gray) lpattern(dash)) ///
	legend(rows(2) size(large) `legpos') ytitle( , axis(1) size(large)) ytitle( , axis(2) size(large)) ///
	xsize(20) ysize(8) ylab(`myla', labsize(medlarge) ang(h))  ylab( , axis(2) labsize(medlarge) ang(h)) xlab( , labsize(medlarge)) 
	
	if "`var'" == "total" {
	graph export "Fig_8a)-`var'_revsh_OW+rev.pdf", as(pdf) replace
	}
	
	if "`var'" == "corp_total" {
	graph export "Fig_8b)-`var'_revsh_OW+rev.pdf", as(pdf) replace
	}
	
	if "`var'" == "all_rev" {
	graph export "Fig_8c)-`var'_revsh_OW+rev.pdf", as(pdf) replace
	}
		restore
}


								* * * * *  E N D  * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
